package com.example.maze.solver;

import com.example.maze.model.Cell;
import com.example.maze.model.Coordinate;

import java.util.List;

/**
 * 寻路结果类，包含路径和统计信息
 * 
 * @author maze-demo
 */
public class SolverResult {
    private final List<Coordinate> path;
    private final int visitedCells;
    private final long timeMillis;
    private final boolean found;
    private final String algorithmName;

    public SolverResult(String algorithmName, List<Coordinate> path, int visitedCells, long timeMillis) {
        this.algorithmName = algorithmName;
        this.path = path;
        this.visitedCells = visitedCells;
        this.timeMillis = timeMillis;
        this.found = path != null && !path.isEmpty();
    }

    public static SolverResult notFound(String algorithmName, int visitedCells, long timeMillis) {
        return new SolverResult(algorithmName, null, visitedCells, timeMillis);
    }

    // Getters
    public List<Coordinate> getPath() {
        return path;
    }

    public int getPathLength() {
        return found ? path.size() : 0;
    }

    public int getVisitedCells() {
        return visitedCells;
    }

    public long getTimeMillis() {
        return timeMillis;
    }

    public boolean isFound() {
        return found;
    }

    public String getAlgorithmName() {
        return algorithmName;
    }

    @Override
    public String toString() {
        if (found) {
            return String.format("%s算法: 找到路径，长度=%d，访问=%d，耗时=%dms", 
                algorithmName, getPathLength(), visitedCells, timeMillis);
        } else {
            return String.format("%s算法: 未找到路径，访问=%d，耗时=%dms", 
                algorithmName, visitedCells, timeMillis);
        }
    }
}